const mongoose = require("./db");
const { getId } = require("../utils/getMethods");

// 订单详情
const orderInfoListSchema = new mongoose.Schema({
  orderNo: {
    // 订单号
    type: Number, // 64971771434285132351990719815828373504
    required: true,
    unique: true,
    default: () => getId,
  },
  activityReduceAmount: {
    // 活动优惠金额
    type: Number, // 2
    required: true,
  },
  couponReduceAmount: {
    // 优惠券优惠金额
    type: Number, // 3
    required: true,
  },
  originalTotalAmount: {
    // 订单原价
    type: Number, // 120
    required: true,
  },
  totalAmount: {
    // 订单总价
    type: Number, // 115
    required: true,
  },
});

// 订单列表
const orderItemListSchema = new mongoose.Schema({
  id: {
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  skuType: {
    type: String,
    required: true,
  },
  skuId: {
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  skuName: {
    type: String,
    required: true,
  },
  imgUrl: {
    type: String,
    required: true,
  },
  skuPrice: {
    type: Number,
    required: true,
  },
  skuNum: {
    type: Number,
    required: true,
  },
  splitActivityAmount: {
    type: Number,
    required: true,
  },
  splitCouponAmount: {
    type: Number,
    required: true,
  },
  splitTotalAmount: {
    type: Number,
    required: true,
  },
});

// 订单记录列表
const orderRecordListSchema = new mongoose.Schema({
  id: {
    // 订单id
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  createTime: {
    // 订单创建时间
    type: String,
  },
  orderNo: {
    // 订单号
    type: String,
  },
  couponId: {
    // 优惠券id
    type: Number,
  },
  totalAmount: {
    // 订单总价
    type: Number,
  },
  activityAmount: {
    // 活动优惠金额
    type: Number,
  },
  couponAmount: {
    // 优惠券优惠金额
    type: Number,
  },
  originalTotalAmount: {
    // 订单原价
    type: Number,
  },
  paymentTime: {
    // 支付时间
    type: String,
  },
  orderItemList: Array, // 订单详情列表
  orderStatus: {
    type: Number, // 订单状态
  },
});
/**
orderStatus订单状态
1000:待付款
2000:待发货
3000:待收货
4000:待评价
5000:已完结
 */

const confirmOrderInfoSchema = new mongoose.Schema({
  id: {
    type: Number,
    required: true,
    unique: true,
    default: () => getId,
  },
  createTime: {
    type: String,
  },
  orderNo: {
    type: String,
  },
  couponId: {
    //订单号
    type: String,
  },
  totalAmount: {
    type: Number,
    default: 0,
  },
  activityAmount: {
    type: Number,
    default: 0,
  },
  couponAmount: {
    type: Number,
    default: 0,
  },
  originalTotalAmount: {
    type: Number,
    default: 0,
  },
  leaderId: {
    type: Number,
  },
  leaderName: {
    type: String,
  },
  leaderPhone: {
    type: Number,
  },
  takeName: {
    type: String,
  },
  receiverName: {
    type: String,
  },
  receiverPhone: {
    type: Number,
  },
  receiverAddress: {
    type: String,
  },
  orderItemList: Array,
});

const confirmPaymentParamsSchema = new mongoose.Schema({
  timeStamp: {
    type: String,
    default: Date.now(),
  },
  package: {
    type: String,
  },
  paySign: {
    type: String,
  },
  signType: {
    type: String,
  },
  nonceStr: {
    type: String,
    default: getId,
  },
});

// 提交订单信息
const submitOrderParamsSchema = new mongoose.Schema({
  couponId: String, // 优惠券id    '0'
  leaderId: Number, // 领导id		3.0337963950277517e+38
  orderNo: Number, // 订单号		6.497177143428513e+37
  receiverName: String, // 收货人姓名
  receiverPhone: Number, // 收货人电话
});

// 订单详情
const orderInfoListModel = mongoose.model(
  "orderInfoList",
  orderInfoListSchema,
  "orderInfoList"
);

// 订单列表
const orderItemListModel = mongoose.model(
  "orderItemList",
  orderItemListSchema,
  "orderItemList"
);

// 订单记录列表
const orderRecordListModel = mongoose.model(
  "orderRecordList",
  orderRecordListSchema,
  "orderRecordList"
);

// 提交订单信息
const submitOrderParamsModel = mongoose.model(
  "submitOrderParams",
  submitOrderParamsSchema,
  "submitOrderParams"
);

module.exports = {
  orderItemListModel,
  orderInfoListModel,
  orderRecordListModel,
  submitOrderParamsModel,
};
